package com.javakc.mes.annual.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javakc.mes.annual.entity.Annual;
import com.javakc.mes.annual.mapper.AnnualMapper;
import com.javakc.mes.annual.service.AnnualService;
import com.javakc.servicebase.config.InstructionQuery;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

@Service
public class AnnualServiceImpl extends ServiceImpl<AnnualMapper, Annual> implements  AnnualService {

    @Override
    public void findPageAnnual(Page<Annual> annualPage, InstructionQuery instructionQuery) {
        QueryWrapper<Annual> queryWrapper = new QueryWrapper<>();
        if(!ObjectUtils.isEmpty(instructionQuery)){
            if(!ObjectUtils.isEmpty(instructionQuery.getName())){
                queryWrapper.like("name",instructionQuery.getName());
            }
            if (!ObjectUtils.isEmpty(instructionQuery.getBeginDate())) {
                queryWrapper.ge("gmt_create", instructionQuery.getBeginDate());
            }
            if (!ObjectUtils.isEmpty(instructionQuery.getEndDate())) {
                queryWrapper.lt("gmt_create", instructionQuery.getEndDate());
            }
        }
        queryWrapper.orderByDesc("gmt_create");
        baseMapper.selectPage(annualPage,queryWrapper);
    }
}
